package com.chauncy.DMS.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.chauncy.DMS.dao.ManagerDaoImplement;

import net.sf.json.JSONObject;

public class UpdateHealthInfoServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ManagerDaoImplement daoImplement = new ManagerDaoImplement();
		int hNub = 0;
		String Deduction = null;
		String The_value = null;
		String health_type = null;
		String Grade = null;
		String Remarks = null;
		int flag = 0;
		String sql = "UPDATE  health_info_table  SET	Deduction = ?,The_Value = ?,Grade = ?,health_type = ?,Att_time = NOW(),Remarks = ? WHERE Health_info_number = ?";		
		//获取ajax 传递来的obj值
		JSONObject object = JSONObject.fromObject(request.getParameter("obj"));
		if(!object.equals("") && object != null){
			System.out.println(object);
			//扣分详细
			Deduction = String.valueOf(object.get("Deduction"));
			//分值
			The_value = String.valueOf(object.get("The_value"));
			//卫生等级
			Grade = String.valueOf(object.get("Grade"));
			//卫生类型
			health_type = String.valueOf(object.get("health_type"));
			//备注
			Remarks = String.valueOf(object.get("Remarks"));
			//卫生唯一ID
			hNub = Integer.parseInt(String.valueOf(object.get("hNub")));
			//缺省值
			Object[] param = {Deduction,The_value,Grade,health_type,Remarks,hNub};
			//执行卫生更新
			flag = daoImplement.updata(sql, param);
			response.getWriter().print(flag);
		}else{	
			
			System.out.println("object is null");
			response.getWriter().print("error");
		}
	}
}
